package com.appbee.user.client.presenter;

import javax.inject.Inject;

import com.appbee.user.client.text.UserInfoStrings;
import com.appbee.user.shared.proxy.WebUserProxy;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;

public class UserInfoActivity extends AbstractActivity
{
	private final View view;

	public interface View extends IsWidget
	{

		void setUserName(String nickName);

		void setLoginOrOutUrl(String label, String url);

	}

	@Inject
	public UserInfoActivity(View view,
							WebUserProxy webUser,
							UserInfoStrings userInfoStrings)
	{
		this.view = view;
		String nickName = webUser.getNickName();
		if(nickName!=null)
		{
			view.setUserName(webUser.getNickName());
			view.setLoginOrOutUrl(	userInfoStrings.signOut(),
									webUser.getLoginOrOutUrl());
		}
		else
		{
			view.setLoginOrOutUrl(	userInfoStrings.signIn(),
									webUser.getLoginOrOutUrl());
			
		}
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus)
	{
		panel.setWidget(view);
	}

}
